{include file="header.html"}
<div id="page_main" class="main-right">
<div id="rightTop">
    <p>{$lang.db}</p>
    <ul class="subnav">
        <li><a class="btn1" href="{url route='db/backup'}">{$lang.backup}</a></li>
        <li><span>{$lang.recover}</span></li>
    </ul>
</div>
<div class="info2 flexigrid">
    <table class="distinction">
        <!--{if $backups}-->
        <thead>
            <tr>
                <th class="w30" class="firstCell"><input type="checkbox" class="checkall" /></th>
                <th align="left" width="350">{$lang.backup_name}</th>
                <th class="align_center">{$lang.add_time}</th>
                <th class="align_center">{$lang.size}</th>
                <th class="align_center">{$lang.total}</th>
                <th class="handler" style="width:200px;">{$lang.handler}</th>
            </tr>
        </thead>
        <!--{/if}-->
        <tbody>
        <!--{foreach from=$backups item=backup}-->
        <tr>
            <td class="align_center w30"><input value="{$backup.name}" class='checkitem' type="checkbox" /></td>
            <td align="left" width="350"><img style="cursor:pointer" backup_name="{$backup.name}" src="{lib file='treetable/images/tv-expandable.gif'}" /> {$backup.name|escape}</td>
            <td class="align_center">{$backup.date|date_format:"%Y.%m.%d %H:%M:%S"}</td>
            <td class="align_center">{$backup.size}KB</td>
            <td class="align_center">{count($backup.vols)}</td>
            <td class="handler bDiv" style=" background:none; width:220px;">
            <a uri="{url route='db/delete' backup_name=$backup.name}" confirm="{$lang.drop_confirm}" class="btn red J_AjaxRequest"><i class="fa fa-trash-o"></i>{$lang.drop}</a> <a href="javascript:;" class="btn blue J_Import" name="{$backup.name}"><i class="fa fa-sign-in"></i>{$lang.import}</a>
            </td>
        </tr>
            <!--{foreach from=$backup.vols item=vol}-->
            <tr class="tatr2" style="display:none" parent="{$backup.name}">
                <td class="firstCell"></td>
                <td align="left" width="350"><img style="margin-left:20px" src="{lib file='treetable/images/tv-item.gif'}" /> {$vol.name|escape}</td>
                <td>{$vol.date|date_format:"%Y.%m.%d %H:%M:%S"}</td>
                <td>{$vol.size}KB</td>
                <td></td>
                <td class="handler bDiv" style=" background:none; width:220px;">
                <a name="drop" href="{url route='db/download' backup_name=$backup.name file=$vol.name}" class="btn green"><i class="fa fa-download"></i>{$lang.download}</a>
                </td>
            </tr>
            <!--{/foreach}-->
        <!--{foreachelse}-->
        <tr class="no_data">
            <td colspan="6">{$lang.no_data}</td>
        </tr>
        <!--{/foreach}-->
        </tbody>
        <tfoot>
            <tr class="tr_pt10">
                <!-- {if $backups} -->
                <td class="align_center"><label for="checkall1">
                    <input id="checkall_2" type="checkbox" class="checkall">
                    </label></td>
                <td colspan="5" id="batchAction"><span class="all_checkbox mt5">
                    <label for="checkall_2">{$lang.checkall}</label>
                    </span>&nbsp;&nbsp;
                    <div class="fbutton J_BatchDel" style="border:0;" confirm="{$lang.drop_confirm}" uri="{url route='db/delete'}" name="backup_name"><div class="del" title="{$lang.batch_del_for_selected}"><span><i class="fa fa-trash"></i>{$lang.batch_del}</span></div></div>
                </td>
                <!--{/if}-->
            </tr>
        </tfoot>
    </table>
</div>
</div>
<script type="text/javascript">
$(function(){
	$("img[backup_name]").click(function(){
        if($(this).attr('expanded')=="true"){
            $(this).attr('src', "{lib file='treetable/images/tv-expandable.gif'}");
            $("tr[parent='"+$(this).attr('backup_name')+"']").hide();
            $(this).attr('expanded', "false");
        }
        else{
            $(this).attr('src', "{lib file='treetable/images/tv-collapsable.gif'}");
            $("tr[parent='"+$(this).attr('backup_name')+"']").show();
            $(this).attr('expanded', "true");
        }
    });
	
	$(".J_Import").click(function(){
		var self = this, status = ".", name = $(this).attr('name'), index = null;
		
		layer.open({ content:lang.db_operate_confirm, btn:['开始还原','关闭'],
			yes:function(i){
				layer.close(i);
				index = layer.open({
					type: 1,
					area: ['400px', '120px'], //宽高
					closeBtn: false,
					move: false,
					content: '<div class="con" style="padding:20px 20px; text-align: center;font-size:14px;">正在还原数据库，请不要关闭！</div>'
				});
				$.post(url(['db/recover']), { name:name}, success, "json");
		 		window.onbeforeunload = function(){ return "正在还原数据库，请不要关闭！" }
			},
			no: function(i) {
				layer.close(i);
			}
		});

		function success(data){
			if(data.status){
				$('.layui-layer-content .con').html(data.info);
       			if(data.gz){
   					data.info += status;
           			if(status.length === 5){
              			status = ".";
           			} else {
           				status += ".";
  					}
				}
 
				if(data.part){
                 	$.post(url(['db/import']), { name:name, "part" : data.part, "start" : data.start}, success, "json");
      			} else {
     				window.onbeforeunload = function(){ return null; }
					setTimeout(function(){
						layer.close(index);
					},2000);
       			}
   			} 
			else 
			{
				$('.layui-layer-content .con').html(data.info);
					setTimeout(function(){
   					layer.close(index);
  				},2000);
			}
		}
	});
});
</script>
{include file="footer.html"}